﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Geometry
{
    [TypeConverter(typeof(VectorConverter))]
    public struct Vector
    {
        public double X { get; set; }
        public double Y { get; set; }

        public Vector(double x, double y)
            : this()
        {
            X = x;
            Y = y;
        }

        public double LengthSquared
        {
            get
            {
                return X*X + Y*Y;
            }
        }

        public double Length
        {
            get
            {
                return Math.Sqrt(LengthSquared);
            }
        }

        public static Point operator +(Point p, Vector v)
        {
            return new Point(p.X + v.X, p.Y + v.Y);
        }

        public static Point operator -(Point p, Vector v)
        {
            return new Point(p.X - v.X, p.Y - v.Y);
        }

        public static Vector operator + (Vector v1, Vector v2)
        {
            return new Vector(v1.X + v2.X, v1.Y + v2.Y);
        }

        public static Vector operator -(Vector v1, Vector v2)
        {
            return new Vector(v1.X - v2.X, v1.Y - v2.Y);
        }

        public static Vector operator *(Vector v, double m)
        {
            return new Vector(v.X * m, v.Y * m);
        }

        public static double AngleBetween(Vector v1, Vector v2)
        {
            var a2 = Math.Atan2(v2.Y, v2.X);
            var a1 = Math.Atan2(v1.Y, v1.X);
            return a2 - a1;
        }
    }
}
